#ifndef METADATA_H
#define METADATA_H


#include "data_global.h"
#include "metaitem.h"


#include <QObject>
#include <QList>
#include <QMetaType>
#include <QPointer>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QStringList>

class Collection;

// XML: Element is the class name without arguments
class DATASHARED_EXPORT MetaData : public QObject
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:
        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
           items = other.items;
           fields = other.fields;
        }

        QList<MetaItemPtr>  items;
        QStringList         fields;
    };

    Q_PROPERTY(QStringList fields READ fields WRITE setFields)

public:

    Q_INVOKABLE MetaData(Collection *parent = 0);
    MetaData(const MetaData& other);

    QStringList fields() const;
    void setFields(const QStringList& fields);

    void addField(const QString& name);
    void insertField(int index, const QString& name);
    void removeField(int index);

    QString fieldName(int index) const;
    int fieldIndex(const QString& name) const;


    void addItem(MetaItem* item);
    void insertItem(int index, MetaItem* item);

    void addItem(const QString &name);
    void insertItem(int index, const QString& name);

    void renameItem(int index, const QString& name);
    void moveItem(int from, int to);

    void removeItem(int index);

    const QList<MetaItemPtr>& items() const;
    MetaItemPtr item(int index) const;

    int indexOf(MetaItem* item) const;


protected:

    QSharedDataPointer<Data> d;

    
};


Q_DECLARE_METATYPE(MetaData*)


typedef QPointer<MetaData> MetaDataPtr;


#endif // METADATA_H


